﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using SoccerLiveScores.ViewModels;

namespace SoccerLiveScores
{
    public partial class MainPage : PhoneApplicationPage
    {
        private ListPageViewModel SelectedItem
        {
            get;
            set;
        }

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
        }

        private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var vm = e.AddedItems[0] as ListPageViewModel;
                if (vm != null)
                {
                    SelectedItem = vm;
                }
            }
        }

        private void btnRefresh_Click(object sender, RoutedEventArgs e)
        {
            SelectedItem.LoadData();
        }

        private void txtFilter_TextChanged(object sender, TextChangedEventArgs e)
        {
            string filter = ((TextBox)sender).Text;
            SelectedItem.UpdateFilter(filter);
        }
    }
}